package org.shj.hadoop.customer;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.hadoop.io.WritableComparable;

public class KeyPair implements WritableComparable<KeyPair> {
	private int year;
	private int temperature;

	public void write(DataOutput out) throws IOException {
		out.writeInt(year);
		out.writeInt(temperature);
	}

	public void readFields(DataInput in) throws IOException {
		this.year = in.readInt();
		this.temperature = in.readInt();
	}

	public int compareTo(KeyPair o) {
		int res = Integer.compare(year, o.getYear());
		if(res == 0){
			return Integer.compare(this.temperature, o.getTemperature());
		}else{
			return res;
		}
	}
	
	public String toString(){
		return year + "\t" + this.temperature;
	}
	
	

	@Override
	public int hashCode() {
		return new HashCodeBuilder(17,37).append(year).append(temperature).toHashCode();
	}

	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public int getTemperature() {
		return temperature;
	}

	public void setTemperature(int temperature) {
		this.temperature = temperature;
	}

}
